package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxTypeYwh;
import cn.stylefeng.guns.modular.lx.mapper.LxTypeYwhMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxTypeYwhParam;
import cn.stylefeng.guns.modular.lx.model.result.LxTypeYwhResult;
import  cn.stylefeng.guns.modular.lx.service.LxTypeYwhService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywh
 * @since 2023-12-04
 */
@Service
public class LxTypeYwhServiceImpl extends ServiceImpl<LxTypeYwhMapper, LxTypeYwh> implements LxTypeYwhService {

    @Override
    public void add(LxTypeYwhParam param){
        LxTypeYwh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxTypeYwhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxTypeYwhParam param){
        LxTypeYwh oldEntity = getOldEntity(param);
        LxTypeYwh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxTypeYwhResult findBySpec(LxTypeYwhParam param){
        return null;
    }

    @Override
    public List<LxTypeYwhResult> findListBySpec(LxTypeYwhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxTypeYwhParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxTypeYwhParam param){
        return param.getLbid();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxTypeYwh getOldEntity(LxTypeYwhParam param) {
        return this.getById(getKey(param));
    }

    private LxTypeYwh getEntity(LxTypeYwhParam param) {
        LxTypeYwh entity = new LxTypeYwh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
